package com.generator.mybatis.generator.core.dao;

import com.generator.mybatis.generator.core.vo.ColumnVO;
import com.generator.mybatis.generator.core.vo.TableVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BaseDao {
    @Results(value= {
            @Result(property="name",column="name"),
            @Result(property="comment",column="comment")
    })
    @Select("SELECT TABLE_NAME as name,TABLE_COMMENT as comment FROM information_schema.TABLES WHERE table_schema=#{database}")
    public List<TableVO> selectTable(@Param("database") String database);

    @Results(value= {
            @Result(property="name",column="name"),
            @Result(property="comment",column="comment"),
            @Result(property="type",column="type"),
            @Result(property="key",column="key"),
            @Result(property="extra",column="extra"),
            @Result(property="columnType",column="columnType")
    })
    @Select("SELECT column_name as `name`,data_type as type,COLUMN_KEY as `key`,extra,COLUMN_COMMENT as `comment`,COLUMN_TYPE as columnType FROM INFORMATION_SCHEMA.Columns WHERE table_name=#{table} AND table_schema=#{database}")
    public List<ColumnVO> selectColumn(@Param("database") String database, @Param("table") String table);
}
